type int = number;
//class ArrayList

export class ArrayList {

  public add(arg1: Object): void {
    this._dynamicArray.push(arg1);
    return;
  }

  public addAll(arg1: int, items: any): void {
    if (Array.isArray(items)) {
      let i = 0;
      while (i < items.length) {
        this._dynamicArray.push(items[i]);
        ++i;
      }
    }
    return;
  }

  public contains(arg1: any): Boolean {
    if (this._dynamicArray.indexOf(arg1) != -1) {
      return true;
    }
    return false;
  }

  public get(arg1: int){
    if (arg1 >= 0 && arg1 <= this._dynamicArray.length - 1) {
      return this._dynamicArray[arg1];
    }
    return null;
  }

  public isEmpty(): Boolean {
    if (this._dynamicArray.length > 0) {
      return false;
    }
    return true;
  }

  public removeByIndex(arg1: int) {
    var loc1 = null;
    var loc2 = 0;
    if (arg1 == 0) {
      return this._dynamicArray.shift();
    }
    if (arg1 == this._dynamicArray.length - 1) {
      return this._dynamicArray.pop();
    }
    if (arg1 > 0 && arg1 < this._dynamicArray.length - 1) {
      loc1 = this._dynamicArray[arg1];
      loc2 = arg1;
      while (loc2 < this._dynamicArray.length - 1) {
        this._dynamicArray[loc2] = this._dynamicArray[loc2 + 1];
        ++loc2;
      }
      this._dynamicArray.pop();
      return loc1;
    }
    return null;
  }

  public remove(arg1: Object): void {
    var loc1 = 0;
    if (this._dynamicArray.indexOf(arg1) != -1) {
      loc1 = this._dynamicArray.indexOf(arg1);
      this.removeByIndex(loc1);
    }
    return;
  }

  public removeAll(arg1: Array<any>): void {
    var loc2 = 0;
    var loc1 = 0;
    while (loc1 < arg1.length) {
      loc2 = this._dynamicArray.indexOf(arg1[loc1]);
      if (loc2 != -1) {
        this.removeByIndex(loc2);
      }
      ++loc1;
    }
    return;
  }

  public size(): int {
    return this._dynamicArray.length;
  }

  public toString(): string {
    return this._dynamicArray.toString();
  }

  public clear(): void {
    this._dynamicArray = [];
  }

  private _dynamicArray: Array<any> = [];
}
